<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
    <div class="nav">
        联机五⼦棋
    </div>
    <div class="login-container">
        <div class="login-dialog">
            <!-- 标题 -->
            <h3>登录</h3>
            <!-- 输⼊⽤⼾名 -->
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <!-- 输⼊密码 -->
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">
            </div>
            <!-- 提交按钮 -->
            <div class="row submit-row">
                <button id="submit">提交</button>
                <button id="register">注册</button>
            </div>
        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js">
    </script>
    <script>
        let submitButton = document.querySelector("#submit");

        submitButton.onclick = function () {
            let usernameInput = document.querySelector("#username");
            let passwordInput = document.querySelector("#password");
            $.ajax({
                type: "post",
                url: "/user/login",
                data: {
                    username: usernameInput.value,
                    password: passwordInput.value
                },
                success: function (result) {
                    if (result == "登入成功") {
                        alert(result);
                        location.href = "game_hall.html";
                    } else {
                        alert(result);
                    }
                }
            });
        }

        let register = document.querySelector("#register");
        register.onclick = function () {
            location.href = "register.html";
        }
    </script>
</body>
</html>

